//	数组格式化json转化字符串
function gg(a, b) {

	a = [];
	a.push(b);
	a = JSON.stringify(a);
	return a;
};
//	格式化json转化字符串
function ggg(a, b) {
	a = b;
	a = JSON.stringify(a);
	return a;
};
//数组对象转化json字符串
function postObj(a) {
	var postObj = {};
	for(var key in a) {
		postObj[key] = a[key];
	}
	return JSON.stringify(postObj);
}
//	开启编辑功能
function disabledY(a) {
	$("." + a + " .addPageDelect").show();
	$("." + a + " input").removeAttr("disabled");
	$("." + a + " textarea").removeAttr("disabled");
	$("." + a + " select").removeAttr("disabled");
	$("." + a + " .el-input span").show();
	$("." + a + " input").removeClass("addPage-none");
	return a = false;
};
//	取消编辑功能
function disabledX(a) {
	$("." + a + " .addPageDelect").hide();
	$("." + a + " input").attr("disabled", "disabled");
	$("." + a + " select").attr("disabled", "disabled");
	$("." + a + " .el-input span").hide();
	$(".addPage_head .el-date-editor span").show();
	$("." + a + " textarea").attr('disabled', "disabled");
	$("." + a + " input").addClass("addPage-none");
	return a = true;
}

//取文件名不带后缀
function GetFileNameNoExt(filepath) {
	//字符串逆转
	function strturn(str) {
		if(str != "") {
			var str1 = "";
			for(var i = str.length - 1; i >= 0; i--) {
				str1 += str.charAt(i);
			}
			return(str1);
		}
	}
	//取文件后缀名
	function GetFileExt(filepath) {
		if(filepath != "") {
			var pos = "." + filepath.replace(/.+\./, "");
			return pos;
		}
	}
	//取文件全名名称
	function GetFileName(filepath) {
		if(filepath != "") {
			var names = filepath.split("\\");
			return names[names.length - 1];
		}
	}
	var pos = strturn(GetFileExt(filepath));
	var file = strturn(filepath);
	var pos1 = strturn(file.replace(pos, ""));
	var pos2 = GetFileName(pos1);
	return pos2;

}
//点击滑动
function addPageJump(i, l) {
	let vm = this;
	vm.mesI = i;
	let a = $("#scrollDiv1").height() + 35;
	let b = a + $("#scrollDiv4").height() + 20;
	let c = b + $("#scrollDiv5").height() + 20;
	let d = c + $("#scrollDiv6").height() + 20;
	let e = d + $("#scrollDiv7").height() + 20;
	//				let f = e + $("#scrollDiv8").height() + 20;
	let g = e + $("#scrollDiv9").height() + 20;
	//				let h = g + $("#scrollDiv10").height() + 20;
	console.log(a)
	if(i == 0) {
		$('.addPageForm').animate({
			scrollTop: 0
		}, 800);
	} else if(i == 1) {
		$('.addPageForm').animate({
			scrollTop: a
		}, 800);
	} else if(i == 2) {
		$('.addPageForm').animate({
			scrollTop: b
		}, 800);
	} else if(i == 3) {
		$('.addPageForm').animate({
			scrollTop: c
		}, 800);
		for(var j = 0; j < l.length; j++) {
			l[j].color = "";
		}
		l[i].color = "addPage_green";
	} else if(i == 4) {
		$('.addPageForm').animate({
			scrollTop: d
		}, 800);
		for(var j = 0; j < l.length; j++) {
			l[j].color = "";
		}
		l[i].color = "addPage_green";
	} else if(i == 5) {
		$(".addPageForm").animate({
			scrollTop: e
		}, 800);
		for(var j = 0; j < l.length; j++) {
			l[j].color = "";
		}
		l[i].color = "addPage_green";
	}
	return 0
};
//預覽圖片
function previewPictures(refs) {
	const elInput = refs.picers;
	const elImg = refs.img;

	function getSrc(a) {
		const reader = new FileReader();
		reader.onload = (e) => {
			const src = e.target.result;
			a.src = src;
		};
		if(elInput.files && elInput.files[0]) {
			reader.readAsDataURL(elInput.files[0]);
		}
		return a.src;
	}
	getSrc(elImg)
};
//預覽圖片
function uploadB64(hhh, EmployeeImg) {
	EmployeeImg.FileName = GetFileNameNoExt(hhh.name);
	EmployeeImg.Type = hhh.type;
	EmployeeImg.Length = hhh.size;
	var reader = new FileReader();
	reader.readAsDataURL(hhh);
	var vm = this;
	reader.onload = function() {
		EmployeeImg.FileString = this.result;
	}
};
//全部禁止
function hideAll() {
	$("form input").attr("disabled", "disabled");
	$("form select").attr("disabled", "disabled");
	$("form .el-input span").hide();
	$(".addPageDelect").hide();
	$("form .el-date-editor span").show();
	$("form textarea").attr('disabled', 'disabled');
	$("form input").addClass("addPage-none");
};
//设置cookie
function setCookie(cname, cvalue, exdays) {
	var d = new Date();
	d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
	var expires = "expires=" + d.toUTCString();
	console.info(cname + "=" + cvalue + "; " + expires);
	document.cookie = cname + "=" + cvalue + "; " + expires;
	console.info(document.cookie);
};
//获取cookie
function getCookie(cname) {
	var name = cname + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while(c.charAt(0) == ' ') c = c.substring(1);
		if(c.indexOf(name) != -1) return c.substring(name.length, c.length);
	}
	return "";
};
//清除cookie
function clearCookie() {
	setCookie("signToken", "", -1);
	setCookie("loginUserId", "", -1);　
	localStorage.clear();
};
// 加法运算

function numAdd(num1, num2) {
	var baseNum, baseNum1, baseNum2;
	try {
		baseNum1 = num1.toString().split(".")[1].length;
	} catch (e) {
		baseNum1 = 0;
	}
	try {
		baseNum2 = num2.toString().split(".")[1].length;
	} catch (e) {
		baseNum2 = 0;
	}
	baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
	return (num1 * baseNum + num2 * baseNum) / baseNum;
};
//減法运算

function numSub(num1, num2) {
	var baseNum, baseNum1, baseNum2;
	var precision;// 精度
	try {
		baseNum1 = num1.toString().split(".")[1].length;
	} catch (e) {
		baseNum1 = 0;
	}
	try {
		baseNum2 = num2.toString().split(".")[1].length;
	} catch (e) {
		baseNum2 = 0;
	}
	baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
	precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
	return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
};
//乘法运算

function numMulti(num1, num2) {
	var baseNum = 0;
	try {
		baseNum += num1.toString().split(".")[1].length;
	} catch (e) {
	}
	try {
		baseNum += num2.toString().split(".")[1].length;
	} catch (e) {
	}
	return Number(num1.toString().replace(".", "")) * Number(num2.toString().replace(".", "")) / Math.pow(10, baseNum);
};
//// 除法运算
//function numDiv(num1, num2) {
//	var baseNum1 = 0, baseNum2 = 0;
//	var baseNum3, baseNum4;
//	try {
//		baseNum1 = num1.toString().split(".")[1].length;
//	} catch (e) {
//		baseNum1 = 0;
//	}
//	try {
//		baseNum2 = num2.toString().split(".")[1].length;
//	} catch (e) {
//		baseNum2 = 0;
//	}
//	with (Math) {
//		baseNum3 = Number(num1.toString().replace(".", ""));
//		baseNum4 = Number(num2.toString().replace(".", ""));
//		return (baseNum3 / baseNum4) * pow(10, baseNum2 - baseNum1);
//	}
//};


	//方法
	export default {
		gg,
		ggg,
		disabledY,
		disabledX,
		postObj,
		GetFileNameNoExt,
		addPageJump,
		previewPictures,
		uploadB64,
		hideAll,
		setCookie,
		getCookie,
		clearCookie,
		numAdd,
		numSub,
		numMulti,
//		numDiv,
	}